using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
using Microsoft.Extensions.DependencyInjection;
using Stee.CAP8.Communication.HttpClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Reflection;

namespace SampleHttpClient
{
    class Program
    {
        static void Main(string[] args)
        {
            CallAPISample();
        }

        static void CallAPISample()
        {
            //Get HttpClientProxy object
            IHttpClientTest proxy = HttpClientProxy.CreateInstance<IHttpClientTest>(
                option =>
                {
                    option.BaseAddress = "http://localhost:5000";
                });

            //Get List
            Console.WriteLine("Initial List");
            var httpList = proxy.Get();
            foreach (var item in httpList)
            {
                Console.WriteLine($"ID: {item.ID}, Name: {item.Name}, CreateTime: {item.CreateTime}");
            }
            Console.WriteLine("");
            //Get Object
            var httpTest = proxy.Get(2);
            Console.WriteLine("Get object ID=2");
            Console.WriteLine($"ID: {httpTest.ID}, Name: {httpTest.Name}, CreateTime: {httpTest.CreateTime}");
            Console.WriteLine("");

            //Post Object
            var httpTestNew = new HttpTest() { ID = 4, Name = "name4", CreateTime = DateTime.Now.AddDays(4) };
            proxy.Post(httpTestNew);

            //Put Object
            httpTest.Name = "name22";
            httpTest.CreateTime = DateTime.Now.AddHours(2);
            proxy.Put(2, httpTest);

            //Delete Object
            proxy.Delete(3);

            //print newest list
            Console.WriteLine("The newest list:");
            httpList = proxy.Get();
            foreach (var item in httpList)
            {
                Console.WriteLine($"ID: {item.ID}, Name: {item.Name}, CreateTime: {item.CreateTime}");
            }

            //set Token and clientId
            proxy.SetToken("token");
            proxy.SetClientID("clientID");

            Console.ReadLine();
        }  
    }
}
